﻿import 'package:get/get.dart';
import 'package:influxdb_client/api.dart';

class InfluxDBClientService extends GetxService {
  InfluxDBClient? _dbClient;
  WriteService? _writeService;

  void connectToDB(String dbUrl, String token, String org, String bucket) {
    _dbClient =
        InfluxDBClient(url: dbUrl, token: token, org: org, bucket: bucket);
    _writeService = _dbClient?.getWriteService(WriteOptions(batchSize: 100));
  }

  WriteService? getDBWriteService() {
    return _writeService;
  }

  @override
  void onClose() {
    _writeService?.flush();
    _writeService?.close();
    super.onClose();
  }
}
